﻿namespace MovieTicket.WebApi.Common
{
    using System.Security.Principal;

    /// <summary>
    ///     Class MovieTicketsPrincipal
    /// </summary>
    public class MovieTicketsPrincipal : IPrincipal
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="MovieTicketsPrincipal" /> class.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        public MovieTicketsPrincipal(string userName)
        {
            UserName = userName;
            Identity = new GenericIdentity(userName);
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets the identity of the current principal.
        /// </summary>
        /// <value>The identity.</value>
        /// <returns>The <see cref="T:System.Security.Principal.IIdentity" /> object associated with the current principal.</returns>
        public IIdentity Identity { get; private set; }

        /// <summary>
        ///     Gets or sets the name of the user.
        /// </summary>
        /// <value>The name of the user.</value>
        public string UserName { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     Determines whether the current principal belongs to the specified role.
        /// </summary>
        /// <param name="role">The name of the role for which to check membership.</param>
        /// <returns>true if the current principal is a member of the specified role; otherwise, false.</returns>
        public bool IsInRole(string role)
        {
            return role.Equals("user");
        }

        #endregion
    }
}